package bounce;

import java.awt.Color;
import junit.framework.TestCase;

/**
 * Test cases to test DynamicRectangleShape.
 * 
 * @author Ken Neth Yeoh
 *
 */

public class TestDynamicRectangleShape extends TestCase {
	private MockPainter painter;
	
	public void setUp() {
		painter = new MockPainter();
	}
	
	public void testShapeWithBounceOffLeft() {
		Color c = new Color(200, 200, 0);
		DynamicRectangleShape shape = new DynamicRectangleShape(10, 50, -15, 15, 40, 40, c);
		shape.paint(painter);
		shape.move(1000,1000);
		shape.paint(painter);
		shape.move(1000,1000);
		shape.paint(painter);
		assertEquals("(rectangle 10,50,40,40)(rectangle 0,65,40,40)(set colour 200,200,0)" +
				"(fill rect 0,65,40,40)(set colour 255,255,255)(rectangle 15,80,40,40)" +
				"(set colour 200,200,0)(fill rect 15,80,40,40)(set colour 255,255,255)", 
				painter.toString());
	}
	
	public void testShapeWithBounceOffRight() {
		Color c = new Color(200, 200, 0);
		DynamicRectangleShape shape = new DynamicRectangleShape(950, 50, 15, 15, 40, 40, c);
		shape.paint(painter);
		shape.move(1000, 1000);
		shape.paint(painter);
		shape.move(1000, 1000);
		shape.paint(painter);
		assertEquals("(rectangle 950,50,40,40)(rectangle 960,65,40,40)(set colour 200,200,0)" +
				"(fill rect 960,65,40,40)(set colour 255,255,255)(rectangle 945,80,40,40)" +
				"(set colour 200,200,0)(fill rect 945,80,40,40)(set colour 255,255,255)", 
				painter.toString());
	}
	
	public void testShapeWithBounceOffTop() {
		Color c = new Color(200, 200, 0);
		DynamicRectangleShape shape = new DynamicRectangleShape(50, 10, 15, -15, 40, 40, c);
		shape.paint(painter);
		shape.move(1000,1000);
		shape.paint(painter);
		shape.move(1000,1000);
		shape.paint(painter);
		assertEquals("(rectangle 50,10,40,40)(rectangle 65,0,40,40)(rectangle 80,15,40,40)", 
				painter.toString());
	}
	
	public void testShapeWithBounceOffBottom() {
		Color c = new Color(200, 200, 0);
		DynamicRectangleShape shape = new DynamicRectangleShape(50, 950, 15, 15, 40, 40, c);
		shape.paint(painter);
		shape.move(1000,1000);
		shape.paint(painter);
		shape.move(1000,1000);
		shape.paint(painter);
		assertEquals("(rectangle 50,950,40,40)(rectangle 65,960,40,40)(rectangle 80,945,40,40)", 
				painter.toString());
	}
	
	public void testShapeWithBounceOffTopLeft() {
		Color c = new Color(200, 200, 0);
		DynamicRectangleShape shape = new DynamicRectangleShape(10, 10, -15, -15, 40, 40, c);
		shape.paint(painter);
		shape.move(1000,1000);
		shape.paint(painter);
		shape.move(1000,1000);
		shape.paint(painter);
		assertEquals("(rectangle 10,10,40,40)(rectangle 0,0,40,40)(set colour 200,200,0)" +
				"(fill rect 0,0,40,40)(set colour 255,255,255)(rectangle 15,15,40,40)" +
				"(set colour 200,200,0)(fill rect 15,15,40,40)(set colour 255,255,255)", 
				painter.toString());
	}
	
	public void testShapeWithBounceOffTopRight() {
		Color c = new Color(200, 200, 0);
		DynamicRectangleShape shape = new DynamicRectangleShape(950, 10, 15, -15, 40, 40, c);
		shape.paint(painter);
		shape.move(1000,1000);
		shape.paint(painter);
		shape.move(1000,1000);
		shape.paint(painter);
		assertEquals("(rectangle 950,10,40,40)(rectangle 960,0,40,40)(set colour 200,200,0)" +
				"(fill rect 960,0,40,40)(set colour 255,255,255)(rectangle 945,15,40,40)" +
				"(set colour 200,200,0)(fill rect 945,15,40,40)(set colour 255,255,255)", 
				painter.toString());
	}
	
	public void testShapeWithBounceOffBottomLeft() {
		Color c = new Color(200, 200, 0);
		DynamicRectangleShape shape = new DynamicRectangleShape(950, 950, 15, 15, 40, 40, c);
		shape.paint(painter);
		shape.move(1000,1000);
		shape.paint(painter);
		shape.move(1000,1000);
		shape.paint(painter);
		assertEquals("(rectangle 950,950,40,40)(rectangle 960,960,40,40)(set colour 200,200,0)" +
				"(fill rect 960,960,40,40)(set colour 255,255,255)(rectangle 945,945,40,40)" +
				"(set colour 200,200,0)(fill rect 945,945,40,40)(set colour 255,255,255)", 
				painter.toString());
	}
	
	public void testShapeWithBounceOffBottomRight() {
		Color c = new Color(200, 200, 0);
		DynamicRectangleShape shape = new DynamicRectangleShape(10, 950, -15, 15, 40, 40, c);
		shape.paint(painter);
		shape.move(1000,1000);
		shape.paint(painter);
		shape.move(1000,1000);
		shape.paint(painter);
		assertEquals("(rectangle 10,950,40,40)(rectangle 0,960,40,40)(set colour 200,200,0)" +
				"(fill rect 0,960,40,40)(set colour 255,255,255)(rectangle 15,945,40,40)" +
				"(set colour 200,200,0)(fill rect 15,945,40,40)(set colour 255,255,255)", 
				painter.toString());
	}
}
